package com.srwl.mytx.domain;

import android.os.Parcel;
import android.os.Parcelable;

import com.alibaba.fastjson.annotation.JSONField;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Transient;

import java.util.Date;

@Entity
public class Message implements Cloneable, Parcelable {

    @Id
    private String id;
    private String fromId;
    private String toId;
    private String cId;
    private Integer type; //大的分类， 系统消息 c2c聊天消息   直播间消息
    private Integer subType; //小的分类， 比如 c2c 下面，分为  文字消息  图片消息 视频消息等
    private Integer state;
    @JSONField(serialize = false)
    private Integer sendState;
    @JSONField(serialize = false)
    private Integer readState;
    private Integer downloadState;
    private Integer uploadState;
    private Integer visible;
    private Integer playTime;
    private Date updated;
    private String content;
    private Integer size; //文件的大小
    private String mimeType;// 媒体类型
    private String previewUrl;//预览图片地址，按目前的设计，只传输大图，预览图由大图生成，所以预览图是本地地址
    private Integer height;//预览图的高度
    private Integer width;//预览图的宽度
    private String localFilePath; //本地文件地址
    private String title;
    private String icon;
    private Date created;
    private String extraData;

    //加载文件失败后，重新加载的次数,不报错进数据库
    //这样每次加载消息后，如果是下载失败状态，都有机会重新下载
    @Transient
    @JSONField(serialize = false)
    private Integer reDownLoadCount;
    //高亮显示关键词
    @Transient
    private String highlightKeyWord;


    public Message() {
    }


    @Generated(hash = 21590424)
    public Message(String id, String fromId, String toId, String cId, Integer type, Integer subType,
            Integer state, Integer sendState, Integer readState, Integer downloadState,
            Integer uploadState, Integer visible, Integer playTime, Date updated, String content,
            Integer size, String mimeType, String previewUrl, Integer height, Integer width,
            String localFilePath, String title, String icon, Date created, String extraData) {
        this.id = id;
        this.fromId = fromId;
        this.toId = toId;
        this.cId = cId;
        this.type = type;
        this.subType = subType;
        this.state = state;
        this.sendState = sendState;
        this.readState = readState;
        this.downloadState = downloadState;
        this.uploadState = uploadState;
        this.visible = visible;
        this.playTime = playTime;
        this.updated = updated;
        this.content = content;
        this.size = size;
        this.mimeType = mimeType;
        this.previewUrl = previewUrl;
        this.height = height;
        this.width = width;
        this.localFilePath = localFilePath;
        this.title = title;
        this.icon = icon;
        this.created = created;
        this.extraData = extraData;
    }


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getFromId() {
        return fromId;
    }

    public void setFromId(String fromId) {
        this.fromId = fromId;
    }

    public String getToId() {
        return toId;
    }

    public void setToId(String toId) {
        this.toId = toId;
    }

    public String getcId() {
        return cId;
    }

    public void setcId(String cId) {
        this.cId = cId;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Integer getSendState() {
        return sendState;
    }

    public void setSendState(Integer sendState) {
        this.sendState = sendState;
    }

    public Integer getReadState() {
        return readState;
    }

    public void setReadState(Integer readState) {
        this.readState = readState;
    }

    public Integer getDownloadState() {
        return downloadState;
    }

    public void setDownloadState(Integer downloadState) {
        this.downloadState = downloadState;
    }

    public Integer getUploadState() {
        return uploadState;
    }

    public void setUploadState(Integer uploadState) {
        this.uploadState = uploadState;
    }

    public Integer getVisible() {
        return visible;
    }

    public void setVisible(Integer visible) {
        this.visible = visible;
    }

    public Integer getPlayTime() {
        return playTime;
    }

    public void setPlayTime(Integer playTime) {
        this.playTime = playTime;
    }

    public Date getUpdated() {
        return updated;
    }

    public void setUpdated(Date updated) {
        this.updated = updated;
    }

    public String getPreviewUrl() {
        return previewUrl;
    }

    public void setPreviewUrl(String previewUrl) {
        this.previewUrl = previewUrl;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getLocalFilePath() {
        return localFilePath;
    }

    public void setLocalFilePath(String localFilePath) {
        this.localFilePath = localFilePath;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String avatar) {
        this.icon = avatar;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public String getMimeType() {
        return mimeType;
    }

    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getHeight() {
        return height;
    }

    public void setHeight(Integer height) {
        this.height = height;
    }

    public Integer getWidth() {
        return width;
    }

    public void setWidth(Integer width) {
        this.width = width;
    }

    public Integer getSubType() {
        return subType;
    }

    public void setSubType(Integer subType) {
        this.subType = subType;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public String getExtraData() {
        return extraData;
    }

    public void setExtraData(String extraData) {
        this.extraData = extraData;
    }

    public String getCId() {
        return this.cId;
    }

    public void setCId(String cId) {
        this.cId = cId;
    }

    public Integer getReDownLoadCount() {
        return reDownLoadCount;
    }

    public void setReDownLoadCount(Integer reDownLoadCount) {
        this.reDownLoadCount = reDownLoadCount;
    }

    public String getHighlightKeyWord() {
        return highlightKeyWord;
    }

    public void setHighlightKeyWord(String highlightKeyWord) {
        this.highlightKeyWord = highlightKeyWord;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "Message{" +
                "id='" + id + '\'' +
                ", fromId='" + fromId + '\'' +
                ", toId='" + toId + '\'' +
                ", cId='" + cId + '\'' +
                ", type=" + type +
                ", subType=" + subType +
                ", state=" + state +
                ", sendState=" + sendState +
                ", readState=" + readState +
                ", downloadState=" + downloadState +
                ", uploadState=" + uploadState +
                ", visible=" + visible +
                ", playTime=" + playTime +
                ", updated=" + updated +
                ", content='" + content + '\'' +
                ", size=" + size +
                ", mimeType='" + mimeType + '\'' +
                ", previewUrl='" + previewUrl + '\'' +
                ", height=" + height +
                ", width=" + width +
                ", localFilePath='" + localFilePath + '\'' +
                ", title='" + title + '\'' +
                ", icon='" + icon + '\'' +
                ", created=" + created +
                ", extraData='" + extraData + '\'' +
                ", reDownLoadCount=" + reDownLoadCount +
                ", highlightKeyWord='" + highlightKeyWord + '\'' +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.fromId);
        dest.writeString(this.toId);
        dest.writeString(this.cId);
        dest.writeValue(this.type);
        dest.writeValue(this.subType);
        dest.writeValue(this.state);
        dest.writeValue(this.sendState);
        dest.writeValue(this.readState);
        dest.writeValue(this.downloadState);
        dest.writeValue(this.uploadState);
        dest.writeValue(this.visible);
        dest.writeValue(this.playTime);
        dest.writeLong(this.updated != null ? this.updated.getTime() : -1);
        dest.writeString(this.content);
        dest.writeValue(this.size);
        dest.writeString(this.mimeType);
        dest.writeString(this.previewUrl);
        dest.writeValue(this.height);
        dest.writeValue(this.width);
        dest.writeString(this.localFilePath);
        dest.writeString(this.title);
        dest.writeString(this.icon);
        dest.writeLong(this.created != null ? this.created.getTime() : -1);
        dest.writeString(this.extraData);
        dest.writeValue(this.reDownLoadCount);
        dest.writeString(this.highlightKeyWord);
    }

    protected Message(Parcel in) {
        this.id = in.readString();
        this.fromId = in.readString();
        this.toId = in.readString();
        this.cId = in.readString();
        this.type = (Integer) in.readValue(Integer.class.getClassLoader());
        this.subType = (Integer) in.readValue(Integer.class.getClassLoader());
        this.state = (Integer) in.readValue(Integer.class.getClassLoader());
        this.sendState = (Integer) in.readValue(Integer.class.getClassLoader());
        this.readState = (Integer) in.readValue(Integer.class.getClassLoader());
        this.downloadState = (Integer) in.readValue(Integer.class.getClassLoader());
        this.uploadState = (Integer) in.readValue(Integer.class.getClassLoader());
        this.visible = (Integer) in.readValue(Integer.class.getClassLoader());
        this.playTime = (Integer) in.readValue(Integer.class.getClassLoader());
        long tmpUpdated = in.readLong();
        this.updated = tmpUpdated == -1 ? null : new Date(tmpUpdated);
        this.content = in.readString();
        this.size = (Integer) in.readValue(Integer.class.getClassLoader());
        this.mimeType = in.readString();
        this.previewUrl = in.readString();
        this.height = (Integer) in.readValue(Integer.class.getClassLoader());
        this.width = (Integer) in.readValue(Integer.class.getClassLoader());
        this.localFilePath = in.readString();
        this.title = in.readString();
        this.icon = in.readString();
        long tmpCreated = in.readLong();
        this.created = tmpCreated == -1 ? null : new Date(tmpCreated);
        this.extraData = in.readString();
        this.reDownLoadCount = (Integer) in.readValue(Integer.class.getClassLoader());
        this.highlightKeyWord = in.readString();
    }

    public static final Creator<Message> CREATOR = new Creator<Message>() {
        @Override
        public Message createFromParcel(Parcel source) {
            return new Message(source);
        }

        @Override
        public Message[] newArray(int size) {
            return new Message[size];
        }
    };
}
